package com.youxue.controller;

import com.alibaba.fastjson.JSONObject;
import com.youxue.entity.CorrectJsonObject;
import com.youxue.entity.ErrorJsonObject;
import com.youxue.entity.LineDetail;
import com.youxue.service.LineDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 15c on 2018/1/20.
 */
@Controller
@RequestMapping("/linedetail")
public class LineDetailController {
    @Autowired
    LineDetailService lineDetailService;

    /**
     * 展示一条线上的所有景点,景点按升序排列
     *
     * @param lineId 路线id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/alinedetailinfo", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
    String getALineDetail(@RequestParam(required = false) Integer lineId) {
        if (null == lineId) {
            ErrorJsonObject errorJsonObject = new ErrorJsonObject(101, "lineId参数为空");
            return JSONObject.toJSONString(errorJsonObject);
        }
        List<LineDetail> lineDetailList=new ArrayList<LineDetail>();
        lineDetailList=lineDetailService.showALineDetails(lineId);
        CorrectJsonObject correctJsonObject=new CorrectJsonObject("查询成功");
        correctJsonObject.setData(lineDetailList);
        return JSONObject.toJSONString(correctJsonObject);
    }

}
